package com.recruit.wechat.controller;


import com.recruit.wechat.controller.model.ApiResultModel;
import org.springframework.web.bind.annotation.RequestMapping;
import com.recruit.wechat.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import com.recruit.wechat.bean.WechatPosition;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 肖守凯
 * @since 2020-08-24
 */
@Controller
@RequestMapping("/WeChatUser/wechatPosition")
public class WechatPositionController extends BaseController{
     /** 主页面 */
    @RequestMapping("admin/main.html")
    public String main(){
       return  "Wechatposition/WechatpositionMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "admin/addWechatPositionHtml")
    public String addWechatPositionHtml( ){
             return "Wechatposition/WechatpositionAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/editWechatPositionHtml")
    public String editWechatPositionHtml(Integer id ,Model model ){


        model.addAttribute("wechatPosition",wechatPositionService.selectWechatPositionByIdWechatPosition(id));




             return "Wechatposition/WechatpositionEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/showWechatPositionHtml")
    public String showWechatPositionHtml(Integer id ,Model model ){


        WechatPosition wechatPosition=new WechatPosition();
        wechatPosition.setPositionId(id);
        /**
         * sql匹配的ID 的条件为=
         */
        ResultPage wechatPositionByPage = wechatPositionService.findWechatPositionByPage(1, 1, wechatPosition);
        /**
         * 取出第一个 对象
         */
        List<WechatPosition> data = wechatPositionByPage.getData();

        System.out.println("data长度"+data.size());
        System.out.println("data:"+data.get(0).toString());

        if(data.size()!=1){
            return null;
        }

        /**
         * 查询 PositionId 的用户
         */
        model.addAttribute("wechatPosition",data.get(0));




             return "Wechatposition/WechatpositionShow";
    }


    /** 分页查询WechatPosition
     * @param page  页码
     * @param limit  查几条
     * @param wechatPosition  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "admin/findWechatPositionByPage")
    @ResponseBody
    public ResultPage findWechatPositionByPage(Integer page, Integer limit,WechatPosition wechatPosition){
             return wechatPositionService.findWechatPositionByPage(page,limit,wechatPosition);
    }

    /** 添加WechatPosition
     * @param wechatPosition  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/addWechatPosition")
    @ResponseBody
    public ApiResultModel saveWechatPosition(WechatPosition wechatPosition  ){
             return wechatPositionService.addWechatPosition(wechatPosition);
    }

    /** 编辑WechatPosition
     * @param wechatPosition  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/editWechatPosition")
    @ResponseBody
    public ApiResultModel editWechatPosition(WechatPosition wechatPosition  ){

             return wechatPositionService.editWechatPosition(wechatPosition);
    }



    /** 删除一条WechatPosition
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/delWechatPosition")
    @ResponseBody
    public ApiResultModel delWechatPosition( Integer id  ){
             return wechatPositionService.delWechatPosition(id);
    }


}
